package mmc.networking;

import mmc.EngineObject;
import mmc.RemoteServer;
import mmc.Scene;
import mmc.cell.ServerCell;
import mmc.server.RemoteClient;

@SuppressWarnings("serial")
public class RequestInitialScene extends Message {

	ServerCell[] ca;
	int playerId;
	String playerName;
	EngineObject spawnPoint;
	
	public RequestInitialScene(String playerName){
		this.playerName = playerName;
	}
	
	@Override
	public void executeOnClient(RemoteServer context) {
		Scene scene = new Scene(context, ca, spawnPoint);
		context.getClient().setScene(scene);
		context.getClient().getScene().remotePlayerId = playerId;
	}
	
	@Override
	public void executeOnServer(RemoteClient context) {
		playerId = context.getPlayer().id;
		spawnPoint = context.getServer().getScene().getSpawnPoint();
		ca = context.getServer().getScene().getCellManager().getSpawnPackage(spawnPoint);
		context.getPlayer().setName(playerName);
		context.post(this);
		context.getPlayer().start();
		context.getPlayer().addKnownChunks(ca);
	}

}
